package com.itbaizhan.springsecuritydemo1.Hander;

import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;

import java.io.IOException;

public class MyHander implements AuthenticationSuccessHandler {
    
    @Override
    public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
        UserDetails userDetails = (UserDetails) authentication.getPrincipal();
        System.out.println("用户名"+userDetails.getUsername());
        System.out.println("密码"+userDetails.getPassword());
        System.out.println("一些操作");
        //因为中间截断了请求过程，所以需要重定向到启动
        response.sendRedirect("/main");
    }
}
